<template>
  <div class="scroll" ref="wrapper">
    <slot></slot>
  </div>
</template>

<script>
import BScroll from 'better-scroll';

export default {
  props: {
    type: {
      type: Number,
      default: 2
    },
    pullUpload: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      scroll: null
    };
  },
  mounted() {
    this.scroll = new BScroll(this.$refs.wrapper, {
      click: true,
      probeType: this.type
    });
    console.log(this.scroll);
    // 监听滚动事件
    this.scroll.on('scroll', position => {
      this.$emit('scroll', position);
    });
  },
  methods: {
    // 滚动
    scrollTo(x, y, time = 300) {
      if (this.scroll) {
        this.scroll.scrollTo(x, y, time);
      }
    },
    // 重新计算
    refresh() {
      this.scroll && this.scroll.refresh();
    }
  }
};
</script>
